<template>
  <div class="parent">
    <echartsDom v-if="isShowEcharts" style="width: 100%; height: 100%" :width="'100%'" :height="'100%'" :option="option" :type="type" />
    <div v-else>
      <px-empty :image-size="50" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref } from "vue";
import echartsDom from "./echartsDom.vue";
import { deviceStat } from "@/api/waterKanban";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  type: {
    type: String,
    default: ""
  }
});
const isShowEcharts = ref(false);
const state = reactive({
  option: {}
});
const { option } = toRefs(state);
setTimeout(() => {
  isShowEcharts.value = true;
  deviceStat({
    classCode: "MACHINE"
  }).then((response: any) => {
    option.value = {
      backgroundColor: props.type == "dark" ? "#001e3b" : "",
      tooltip: {
        confine: true
      },
      grid: {
        top: "0px",
        left: "0px",
        right: "30px",
        bottom: "-20px",
        containLabel: true
      },
      xAxis: {
        show: false,
        type: "value"
      },
      yAxis: {
        axisTick: {
          show: false // 不显示坐标轴刻度线
        },
        axisLine: {
          show: false // 不显示坐标轴线
        },
        type: "category",
        data: ["总报警", "已解决", "待解决"]
      },
      series: [
        {
          name: "设备报警",
          type: "bar",
          label: {
            show: true,
            position: "right"
          },
          data: [response.alarmStat.total, response.alarmStat.done, response.alarmStat.undone],
          barWidth: "18px",
          itemStyle: {
            normal: {
              color: function (params) {
                let colorList = props.type == "dark" ? ["#F9D423", "#00FF9B", "#FF0844"] : ["#F87171", "#19D08D", "#FFD360"];
                let colorItem = colorList[params.dataIndex];
                return colorItem;
              }
            }
          }
        }
      ]
    };
  });
}, 1000);
</script>

<style scoped lang="scss">
.parent {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
